﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace BTM_Client_Application
{
    /// <summary>
    /// Логика взаимодействия для LoadingWindow.xaml
    /// </summary>
    public partial class LoadingWindow
    {
        private static LoadingWindow _loadWindow;

        private delegate void VoidDelegate();

        private LoadingWindow()
        {
            InitializeComponent();
        }

        public static void ShowWindow()
        {
            var thread = new Thread(() =>
            {
                _loadWindow = new LoadingWindow();
                _loadWindow.Show();

                _loadWindow.Closed += (sender2, e2) =>
                    _loadWindow.Dispatcher.InvokeShutdown();

                System.Windows.Threading.Dispatcher.Run();
            });
            thread.SetApartmentState(ApartmentState.STA);
            thread.Start();
        }

        public static void CloseWindow()
        {
            _loadWindow.Dispatcher.Invoke(new VoidDelegate(() => _loadWindow.Close()));
        }
    }
}
